﻿// =================================================================== 
// 业务逻辑层(GDIT.BLL)
//====================================================================
// 文件：BDepartment.cs
// 项目名称：学院网站
// 创建时间：2012-08-12
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：部门信息操作逻辑
// ===================================================================
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using GDIT.Base.LogHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Model;

namespace GDIT.BLL
{
    public class BDepartment
    {
        private Pattern.DALAbstractFactory dataFactory = DataProvider.defaultProvider;

        /// <summary>
        /// 增加部门
        /// </summary>
        /// <param name="department">需要新增的部门对象</param>
        /// <returns>1: 更新成功 0：更新失败</returns>
        public bool InsertDepartment(Mtb_Department department)
        {
            Logger.Info(String.Format("部门名称[{0}]", department.DepartmentName));
            int result = dataFactory.DALDepartmentProvider.InsertDepartment(department);
            if (result == 1)
            {
                Logger.Info("Insert success");
                return true;
            }
            else
            {
                Logger.Info("Insert false");
                return false;
            }
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="department">需要删除的部门对象</param>
        /// <returns>1: 更新成功 0：更新失败</returns>
        public bool DeleteDepartment(Mtb_Department department)
        {
            Logger.Info(String.Format("部门名称[{0}]", department.DepartmentName));
            int result = dataFactory.DALDepartmentProvider.DeleteDepartment(department);
            if (result == 1)
            {
                Logger.Info("Delete success");
                return true;
            }
            else
            {
                Logger.Info("Delete false");
                return false;
            }
        }

        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="department">需要更新的部门对象</param>
        /// <returns>1: 更新成功 0：更新失败</returns>
        public bool UpdateDepartment(Mtb_Department department)
        {
            Logger.Info(String.Format("部门ID[{0}]", department.OID));
            int result = dataFactory.DALDepartmentProvider.UpdateDepartment(department);
            if (result == 1)
            {
                Logger.Info("Update success");
                return true;
            }
            else
            {
                Logger.Info("Update false");
                return false;
            }
        }

        /// <summary>
        /// 查询所有的部门
        /// </summary>
        /// <returns>所有部门的列表</returns>
        public XPCollection SelectAllDepartment()
        {
            return dataFactory.DALDepartmentProvider.SelectAllDepartment();
        }

        /// <summary>
        /// 查询单一的部门对象
        /// </summary>
        /// <param name="department">需要查询的单一部门对象</param>
        /// <returns>单一部门对象</returns>
        public Mtb_Department SelectDepartmentByDepart(Mtb_Department department)
        {
            return dataFactory.DALDepartmentProvider.SelectDepartmentByDepart(department);
        }
    }
}
